package com.adingxiong.springsecurityoauth2.oauth.service;

import com.adingxiong.springsecurityoauth2.oauth.entity.MySecurityUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import sun.security.util.Password;

/**
 * @ClassName UserDetailService
 * @Description TODO
 * @Author xiongchao
 * @Date 2020/10/29 11:25
 **/
@Service
public class MyUserDetailService implements UserDetailsService {

    @Autowired
    private PasswordEncoder passwordEncoder;


    @Override
    public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {

        MySecurityUser user = new MySecurityUser();
        user.setUsername(s);
        user.setPassword(passwordEncoder.encode("123456"));

        return new User(s,user.getPassword(),user.isEnable(),user.isAccountNonExpired(),user.isCredentialsNonExpired(),
                user.isAccountNonLocked(),AuthorityUtils.commaSeparatedStringToAuthorityList("user:add"));
    }
}
